package com.czmh.etc.entity.sys;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table(name = "sysrole")
@DynamicInsert(true)
@DynamicUpdate(true)
public class SysRole implements java.io.Serializable {

	/**
     * 
     */
    private static final long serialVersionUID = 6493990029575060270L;
    private String id;
	private SysRole trole;
	private String name;
	private String remark;
	private Integer seq;
	private Set<SysRole> sysroles = new HashSet<SysRole>(0);
	private Set<SysResource> sysresources = new HashSet<SysResource>(0);
	private Set<SysUser> sysusers = new HashSet<SysUser>(0);

	public SysRole() {
	}

	public SysRole(String id, String name) {
		this.id = id;
		this.name = name;
	}

	public SysRole(String id, SysRole trole, String name, String remark, Integer seq, Set<SysRole> sysroles, Set<SysResource> sysresources, Set<SysUser> sysusers) {
		this.id = id;
		this.trole = trole;
		this.name = name;
		this.remark = remark;
		this.seq = seq;
		this.sysroles = sysroles;
		this.sysresources = sysresources;
		this.sysusers = sysusers;
	}

	@Id
	@Column(name = "ID", nullable = false, length = 36)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PID")
	public SysRole getSysrole() {
		return this.trole;
	}

	public void setSysrole(SysRole trole) {
		this.trole = trole;
	}

	@Column(name = "NAME", nullable = false, length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "REMARK", length = 200)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "SEQ")
	public Integer getSeq() {
		return this.seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "sysrole")
	public Set<SysRole> getSysroles() {
		return this.sysroles;
	}

	public void setSysroles(Set<SysRole> sysroles) {
		this.sysroles = sysroles;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "sysrole_sysresource", joinColumns = { @JoinColumn(name = "SYSROLE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "SYSRESOURCE_ID", nullable = false, updatable = false) })
	public Set<SysResource> getSysresources() {
		return this.sysresources;
	}

	public void setSysresources(Set<SysResource> sysresources) {
		this.sysresources = sysresources;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "sysuser_sysrole", joinColumns = { @JoinColumn(name = "SYSROLE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "SYSUSER_ID", nullable = false, updatable = false) })
	public Set<SysUser> getSysusers() {
		return this.sysusers;
	}

	public void setSysusers(Set<SysUser> sysusers) {
		this.sysusers = sysusers;
	}

}
